#include "UdpClient.hpp"
#include "Thread.hpp"
#include <memory>

using namespace ThreadModule;

int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cerr << "Usage " << argv[0] << " ip port" << std::endl;
        exit(1);
    }
    std::string ip = argv[1];
    uint16_t port = std::stoi(argv[2]);
    std::unique_ptr<UdpClient> uclt = std::make_unique<UdpClient>(ip, port); // C++14

    // 创建两个线程分别负责 收发消息
    Thread sender("sender-thread", std::bind(&UdpClient::SendMsg, uclt.get(), std::placeholders::_1));
    Thread recver("recver-thread", std::bind(&UdpClient::RecvMsg, uclt.get(), std::placeholders::_1));

    sender.start();
    recver.start();

    sender.join();
    recver.join();
    return 0;
}